function showError (msg) {
	var errorDiv = document.getElementById('error')
	errorDiv.innerText = msg
}

function updatePwd() {
	var oldPwd = $("#oldPwd").val();
	var newPwd = $("#newPwd").val();
	var newPwd1 = $("#newPwd1").val();
	if (!oldPwd) {
		showError('请输入旧密码')
		return
	}
	if (newPwd != newPwd1) {
		showError("两次密码不一致");
		return
	}
	var publicKey = document.getElementById('publicKey').value
	var encrypt = new JSEncrypt()
	encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + publicKey
			+ '-----END PUBLIC KEY-----');
	var data = {
		oldPwd : encrypt.encrypt($("#oldPwd").val()),
		newPwd : encrypt.encrypt($("#newPwd").val())
	};

	$.ajax({
		url : "api/user/updatePwd",
		contentType : "application/json",
		data : JSON.stringify(data),
		type : "POST",
		dataType : "json",
		success : function(data) {
			if (data.success) {
				alert("修改成功");
				window.location.href = '/index'
			} else {
				showError(data.msg)
			}
		},
		error : function(data) {
			showError("修改失败");
		}
	});
}